using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Terra.Data.Context;
using Terra.Data.Repository;
using Terra.Data.Repository.Identity;
using Terra.Data.Repository.Logging;
using Terra.Data.UnitOfWork;

namespace Terra.Data.Extensions;

/// <summary>
/// 服务集合扩展
/// </summary>
public static class ServiceCollectionExtensions
{
    /// <summary>
    /// 添加数据访问服务
    /// </summary>
    /// <param name="services">服务集合</param>
    /// <returns>服务集合</returns>
    public static IServiceCollection AddDataAccess(this IServiceCollection services)
    {
        // 注册工作单元
        services.AddScoped<IUnitOfWork, UnitOfWork.UnitOfWork>();

        // 注册通用仓储
        services.AddScoped(typeof(IRepository<,>), typeof(RepositoryBase<,>));

        // 注册仓储
        services.AddScoped<IUserRepository, UserRepository>();
        services.AddScoped<IRoleRepository, RoleRepository>();
        services.AddScoped<IMenuRepository, MenuRepository>();
        services.AddScoped<IRefreshTokenRepository, RefreshTokenRepository>();
        services.AddScoped<IExceptionLogRepository, ExceptionLogRepository>();

        return services;
    }
}